// ==UserScript==
// @name         教材下载
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://basic.smartedu.cn/tchMaterial/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=claude.ai
// @grant        none
// @run-at document-end
// ==/UserScript==

(function() {
  'use strict';
  const url = window.location.href
  const urlParams = new URLSearchParams(url)
  const paramObj = {};
  for (let [key, value] of urlParams) {
      paramObj[key] = value;
    }
  console.log(paramObj)
  const fileId = paramObj.contentId
  let downloadURL = `https://r2-ndr.ykt.cbern.com.cn/edu_product/esp/assets/${fileId}.pkg/pdf.pdf`
  const btn = document.createElement('button');
  btn.textContent = '下载';
  btn.onclick = () => {
      let iframeURL = document.getElementById("pdfPlayerFirefox").src
      const iURLParams = new URL(iframeURL).searchParams
      const iParamObj = {}
      for(let[key , value] of iURLParams)
      {
        iParamObj[key] = value;
      }
      if(iParamObj.file)
      {
        downloadURL = iParamObj.file.replace(/-private/g,'')
      }
      console.log('click:',downloadURL)
      window.open(downloadURL, '_blank');
    };

    document.body.prepend(btn);
})();